package com.ayf.payment.game.api.auths;

import com.ayf.payment.game.api.bean.AuthorizationInfo;
import com.ayf.payment.game.api.type.AuthorizationType;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liudong on 10/12/15.
 * OAuth的授权方式
 */
@Component("oAuthAuthorization")
public class OAuthAuthorization extends AbstractAuthorization {

    @Override
    public AuthorizationInfo getAuthorizationInfoFromRequestHeader(HttpServletRequest request) {
        AuthorizationInfo authorizationInfo = new AuthorizationInfo();
        authorizationInfo.setAuthType(AuthorizationType.OAUTH);

        //授权信息
        String authorization = request.getHeader("Authorization");
        if (StringUtils.isNotBlank(authorization)) {
            String[] arrs = authorization.split(" ");
            if (arrs != null && arrs.length == 2) {
                authorizationInfo.setAuthValue(arrs[1]);
            }
        }

        return authorizationInfo;
    }


}
